package com.ztk.collection._list;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/*
    for循环和Stream流
 */
public class ForAndStream {

    public static void main(String[] args) {
        LinkedList<Integer> linkedList = getLinkedList();
        long startTime = System.currentTimeMillis();
        linkedList.stream().forEach(e -> {});
        System.out.println("Strem()耗时为：" + (System.currentTimeMillis() - startTime));
        startTime = System.currentTimeMillis();
        for (int i = 0; i < linkedList.size(); i++) {
            linkedList.get(i);
        }
        System.out.println("fori耗时为：" + (System.currentTimeMillis() - startTime));
    }

    private static LinkedList<Integer> getLinkedList() {
        LinkedList<Integer> list = new LinkedList<>();
        for (int i = 0; i < 1900; i++) {
            list.add(i);
        }
        return list;
    }

    private static ArrayList<Integer> getArrayList() {
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            list.add(i);
        }
        return list;
    }
}
